package security.Roles;

import java.util.Vector;

public class VectorGroup extends Group {
	
	private String groupName;
	
	private Vector<Privilege> groupPrivileges;
	private Vector<User> groupUsers;
	
	public VectorGroup(String groupName) {
		this.groupName = groupName;
		this.groupPrivileges = new Vector<Privilege>();
		this.groupUsers = new Vector<User>();
	}		
	
	public Vector<Privilege> getGroupPrivileges() {
		return groupPrivileges;
	}
	public void delGroupPrivilege(Privilege p) {		
		groupPrivileges.remove(p);
	}
	public void addGroupPrivilege(Privilege p) {		
		groupPrivileges.add(p);
	}	
	public void setGroupPrivileges(Vector<Privilege> groupPrivileges) {
		this.groupPrivileges = groupPrivileges;
	}
	public Vector<User> getGroupUsers() {
		return groupUsers;
	}
	public void addGroupUsers(User u) {
		groupUsers.add(u);
	}
	public void delGroupUsers(User u) {
		groupUsers.remove(u);
	}	
	public void setGroupUsers(Vector<User> groupUsers) {
		this.groupUsers = groupUsers;
	}
	public String getGroupName() {
		return groupName;
	}
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}
	
	private static Vector<Group> allGroups = new Vector<Group>();

	
	public static boolean addGroup(Group g) {		
		return allGroups.add(g);
	}
	public static boolean saveGroup(Group g) {
		// not needed
		return true;
	}
	public static boolean delGroup(Group g) {
		return allGroups.remove(g);
	}
	public static Vector<Group> getGroups() {
		return allGroups;
	}
	public static Group getGroupByName(String groupName) {
		for (int i=0;i<allGroups.size();i++){ 
			if (allGroups.get(i).getGroupName().equals(groupName)) {
				return allGroups.get(i);
			}
		}
		return null;
	}		
	
}
